package top.i89ck.modules.utils;

import top.i89ck.modules.model.User;

/**
 * 登录用户
 *
 * @author Seiya
 */
public final class Subject {

    /**
     * 线程变量
     */
    private static final ThreadLocal<Object> LOCAL = new ThreadLocal<>();

    /**
     * 设置当前登录用户
     *
     * @param subject
     */
    public static void set(Object subject) {
        LOCAL.set(subject);
    }

    /**
     * 获取当前登录用户
     *
     * @return
     */
    public static Object get() {
        return LOCAL.get();
    }

    /**
     * 移除当前登录用户
     */
    public static void remove() {
        LOCAL.remove();
    }

    /**
     * 获取当前登录用户
     *
     * @return
     */
    public static User getSessionUser() {
        return (User) get();
    }
}
